package org.six;

import java.io.*;
import java.util.zip.*;

/**
 * 压缩类
 */
public class TestGZIPOutput {
    public static void main(String[] args) throws IOException {
        String dir = System.getProperty("user.dir");
        String s = File.separator;
        String from = dir + s + "abc.mp4";
        String to = dir + s + "dog.zip";
        // 输入流
        // GZIPInputStream gis = new GZIPInputStream( new FileInputStream( from ) );
        InputStream is = new FileInputStream( from );
        // GZIPOutputStream gos = new GZIPOutputStream( new FileOutputStream( to ) );
        ZipOutputStream gos = new ZipOutputStream( new FileOutputStream( to ));
        gos.putNextEntry( new ZipEntry("abc.mp4") );
        byte[] b = new byte[1024];
        int count = 0;      // 用来记录读取了多少
        while ( (count = is.read(b) ) != -1 ) {
            gos.write(b, 0, count);     // 将读取到的内容写入文件
        }
        is.close();
        gos.close();
    }
}
